package com.gec.hawaste.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gec.hawaste.entity.SysRole;
import com.gec.hawaste.mapper.SysRoleMapper;
import com.gec.hawaste.service.ISysRoleService;
import com.gec.hawaste.vo.SysRoleDo;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author chenxys
 * @since 2022-07-01
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Override
    public IPage<SysRoleDo> selectByCondition(IPage<SysRoleDo> page, Map map) {
        QueryWrapper<SysRoleDo> query = new QueryWrapper<>();
        query.eq(map.containsKey("dataScope") && !ObjectUtils.isEmpty(map.get("dataScope")),"data_scope",map.get("dataScope"))
                .eq(map.containsKey("id") && !ObjectUtils.isEmpty(map.get("id")),"office_id",map.get("id"))
                .like(map.containsKey("name") && !ObjectUtils.isEmpty(map.get("name")),"name",map.get("name"))
                .like(map.containsKey("remarks") && !ObjectUtils.isEmpty(map.get("remarks")),"remarks",map.get("remarks"));
        return baseMapper.selectByCondition(page,query);
    }

    @Override
    public SysRoleDo getByRoleId(Long id) {
        QueryWrapper<SysRoleDo> query = new QueryWrapper<>();
        query.eq("sys_role.id",id);
        return baseMapper.getByRoleId(query);
    }
}
